﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Library.Wcf;
using log4net;

namespace MvcApplication3.Controllers
{
    public class DeviceController : Controller
    {
        private static readonly ILog Log = LogManager.GetLogger("DeviceController");

        public ActionResult Index()
        {
            if (Request.IsAuthenticated)
            {
                Log.Info("Index_start");
                var deviceClient = new DeviceWcfClient("http://pi:4321/Device");
                var devices = deviceClient.GetAllWithData();


                Log.Info("About_end");

                deviceClient.Close();
                return View("IndexAuthenticated", devices);

            }
            return View();
        }

        public ActionResult ChangePin(int address, int pin, bool value)
        {
            var deviceClient = new DeviceWcfClient("http://pi:4321/Device");
            deviceClient.WriteDevicePin(address, pin, value);
            deviceClient.Close();

            return RedirectToAction("Index");
        }

    }
}
